package com.roncoo.education.course.service.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.education.course.service.dao.CourseRateDao;
import com.roncoo.education.course.service.dao.impl.mapper.CourseRateMapper;
import com.roncoo.education.course.service.dao.impl.mapper.entity.CourseRate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseRateDaoImpl implements CourseRateDao {

    @Autowired
    private CourseRateMapper courseRateMapper;

    @Override
    public int save(CourseRate courseRate) {
        int insert = courseRateMapper.insert(courseRate);
        return insert;
    }

    @Override
    public CourseRate getById(Long id) {
        return courseRateMapper.selectById(id);
    }

    @Override
    public int updateById(CourseRate courseRate) {
        return courseRateMapper.updateById(courseRate);
    }

    @Override
    public int deleteById(Long id) {
        return courseRateMapper.deleteById(id);
    }

    @Override
    public Page<CourseRate> page(Integer pageCurrent, Integer pageSize, Long userNo) {
        Page<CourseRate> page = new Page<>(pageCurrent, pageSize);
        QueryWrapper<CourseRate> wrapper = new QueryWrapper<CourseRate>().eq("user_no", userNo);
        Page<CourseRate> courseRatePage = courseRateMapper.selectPage(page, wrapper);
        return courseRatePage;
    }
}
